package win.larryzeal.thymeleaf.web.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import win.larryzeal.thymeleaf.entity.Author;
import win.larryzeal.thymeleaf.entity.Book;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * Created by 张少昆 on 2017/10/20.
 */
@Controller
@RequestMapping( "/" )
public class IndexController {

	@RequestMapping( value = {"/", "/index.html"} )
	public String index(Map map){
		Author author = new Author();
		author.setName("Larry");
		author.setAge(18);
		author.setSex(true);

		Book book = new Book();
		book.setAuthor(author);
		book.setName("Larry's Talk");
		book.setPrice(99.99);
		book.setSn("157-999-sn");

		map.put("book", book);

		List<Book> list = new ArrayList<>(10);
		for(int i = 0; i < 10; i++){
			Book _book = new Book();
			_book.setAuthor(author);
			_book.setName("Larry's Talk");
			_book.setPrice(99.99 + i);
			_book.setSn("157-999-sn-" + i);
			list.add(_book);
		}
		map.put("books", list);

		return "index";
	}
}
